package com.dwjm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dwjm.entity.Basic;
import com.dwjm.service.BasicService;

/**
 * 基本信息表Controller层
 * 
 * @date 2016年12月23日
 * @auther luans
 */
@Controller
@RequestMapping("basicctr")
public class BasicController {

	@Resource
	private BasicService basicServiceImpl;

	/**
	 * 去论坛概况页面
	 * 
	 * @param ModelAndView
	 * @return int
	 * @date 2016年12月23日
	 * @auther luans
	 */
	@RequestMapping("bbsbasic")
	public ModelAndView bbsBasic(Basic basic) {
		ModelAndView mv = new ModelAndView();
		Basic bas = basicServiceImpl.selectByPrimaryKey(1);

		if (basic.getMarkManage() == 2) {

			basicServiceImpl.updateByPrimaryKey(basic);
			mv.setViewName("/manager/bbs/bbsBasicManage");
		} else if (basic.getMarkManage() == 3) {

			mv.setViewName("/manager/bbs/bbsBasic");
		}
		mv.addObject("basic", bas);

		return mv;
	}

	/**
	 * 去联系我们页面
	 * 
	 * @param ModelAndView
	 * @return int
	 * @date 2016年12月23日
	 * @auther luans
	 */
	@RequestMapping("bbscontact")
	public ModelAndView bbsContact(Basic basic) {
		ModelAndView mv = new ModelAndView();
		Basic bas = basicServiceImpl.selectByPrimaryKey(2);
		Map<Object, Object> map = new HashMap<Object, Object>();
		String[] arary = bas.getBasContent().split("@##");

		map.put("tel", arary[0]);
		map.put("fax", arary[1]);
		map.put("email", arary[2]);
		map.put("address", arary[3]);
		map.put("postcode", arary[4]);
		map.put("mapimg", arary[5]);

		if (basic.getMarkManage() == 2) {
			mv.setViewName("/manager/system/contactUsManage");
		} else if (basic.getMarkManage() == 3) {

			mv.setViewName("/manager/system/contactUs");
		}
		bas.setMarkManage(basic.getMarkManage());
		mv.addObject("basic", bas);
		mv.addObject("map", map);

		return mv;
	}

	/**
	 * 去诚聘精英页面
	 * 
	 * @param ModelAndView
	 * @return int
	 * @date 2016年12月23日
	 * @auther luans
	 */
	@RequestMapping("bbsrecruit")
	public ModelAndView bbsRecruit(Basic basic) {
		ModelAndView mv = new ModelAndView();
		Basic bas = basicServiceImpl.selectByPrimaryKey(3);
		if (basic.getMarkManage() == 2) {
			mv.setViewName("/manager/system/joinUsManage");
		} else if (basic.getMarkManage() == 3) {

			mv.setViewName("/manager/system/joinUs");
		}
		bas.setMarkManage(basic.getMarkManage());
		mv.addObject("basic", bas);

		return mv;
	}

	/**
	 * 编辑论坛概况页面
	 * 
	 * @param ModelAndView
	 * @return ModelAndView
	 * @date 2016年12月24日
	 * @auther luans
	 */
	@RequestMapping("bbsbasicmanage")
	public ModelAndView bbsBasicManage(Basic basic) {
		if (basic.getMarkManage() == 2) {
			basicServiceImpl.updateByPrimaryKey(basic);
		}
		basic.setMarkManage(3);
		if (basic.getBasId() == 1) {
			return bbsBasic(basic);
		} else if (basic.getBasId() == 2) {
			return bbsContact(basic);
		} else if (basic.getBasId() == 3) {
			return bbsRecruit(basic);
		}
		return bbsBasic(basic);
	}

	/**
	 * PC端：去基础信息页面：论坛概况、联系我们、诚聘精英  
	 * 
	 * @param ModelAndView
	 * @return ModelAndView
	 * @date 2016年12月27日
	 * @auther luans
	 */
	@RequestMapping("pcbbsbasic")
	public ModelAndView pcbbsBasic(Integer id) {
		ModelAndView mv = new ModelAndView();
		Basic bas = new Basic();
		if (id == 1) {
			bas = basicServiceImpl.selectByPrimaryKey(1);
			mv.setViewName("/pc/bbs/bbsBasic");
		} else if (id == 2) {
			bas = basicServiceImpl.selectByPrimaryKey(2);
			Map<Object, Object> map = new HashMap<Object, Object>();
			String[] arary = bas.getBasContent().split("@##");

			map.put("tel", arary[0]);
			map.put("fax", arary[1]);
			map.put("email", arary[2]);
			map.put("address", arary[3]);
			map.put("postcode", arary[4]);
			map.put("mapimg", arary[5]);

			mv.addObject("map", map);
			mv.setViewName("/pc/bbs/contactUs");
		} else if (id == 3) {

			bas = basicServiceImpl.selectByPrimaryKey(3);
			mv.setViewName("/pc/bbs/joinUs");
		}

		mv.addObject("basic", bas);

		return mv;
	}
}
